﻿<?php 
require_once 'functions.php';

$sql = getItemQuery($cat)
		. " LIMIT ".(NUM_MORE_NEWS + 1); // 1 is one main news display on the left side

$result = dbQuery($sql);
$count = dbNumRows($result);
$countMoreNews = min($count, NUM_MORE_NEWS);
//var_dump($result);
//echo '<br /><br /><br />'.$sql;
?>
<?php if ($count > 0) {
	$row = dbFetchAssoc($result);
	$id = $row['id'];
	$name = $row['ten'];
	$summary = getTomtat($row['tomtat'], MAIN_SUMMARY_TEXT_LENGTH);

?>

<div id="cat_<?php echo $cat; ?>" class="cat-widget">
	<h3>
		<a title="" href="javascript:viewList('<?php echo $cat; ?>', '<?php echo $catName; ?>');"><?php echo $catName; ?></a>
		<a class="minimize"></a>
	</h3>
	<div class="container">
		<div class="cpost">
			<div class="thumb">
				<a rel="#custom2" href="javascript:viewArticleAjax('<?php echo $cat; ?>', <?php echo $id; ?>)">
					<img src="images/common/article_default.jpg" width="100" height="75"></img>
				</a>
			</div>
			<div class="info">
				<a class="dark_perm" title="<?php echo $name; ?>" href="javascript:viewArticle('<?php echo $cat; ?>', <?php echo $id; ?>)">
					<?php echo $name; ?>
				</a>
				<p style="color:black;"><?php echo $summary; ?></p><div class="clear"></div>
				<ul class="ex">
					<li class="cont"><a href="javascript:viewArticle('<?php echo $cat; ?>', <?php echo $id; ?>)">Ðọc tiếp</a></li>
				</ul><div class="clear"></div>
			</div>
		</div>
		
		<ul class="more_stories">
			<?php for ($news_index = 0; $news_index < $countMoreNews; $news_index++) { 
				$row = dbFetchAssoc($result);
				$id = $row['id'];
				$name = $row['ten'];
			?>
			<li style="display: list-item; ">
				<a href="javascript:viewArticle('<?php echo $cat; ?>', <?php echo $id; ?>)" 
					title="<?php echo $name; ?>" class="animate">
						<span class="smallimg"><img src="images/common/article_default.jpg" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" width="32" height="32"></span>
						<span class="smalltitle"><?php echo $name; ?></span>
				</a>
			</li>
			<?php } ?>
		</ul>
		<ul class="ex2">
			<li class="cont"><a href="javascript:viewList('<?php echo $cat; ?>', '<?php echo $catName; ?>');">Xem tất cả</a></li>
		</ul>
		<div class="clear"></div>
	</div>
	<div class="footer"></div>
	<div class="clear"></div>
</div>

<?php }; ?>
